import type { ApiPagination } from '#types/utils'
import { requestClient } from '../request'
import type { sellerItemForm, sellerPageListItem } from './model/accountInfoModel'
import { useAppConfig } from '@vben/hooks'
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD)

// 账号信息
export default class AccountInfoApi {
    static get inst() {
        return AccountInfoApi._inst || (AccountInfoApi._inst = new AccountInfoApi())
    }
    private static _inst: AccountInfoApi
    add(params: Partial<sellerItemForm>) {
        return requestClient.post<null>('/buser/add', params)
    }
    approval(data: { approvalMessage?: string; approvalStatus: number; ids: number[] }) {
        return requestClient.put<boolean>('/orders/approval', data)
    }
    delete(ids: Array<number | string>) {
        return requestClient.delete<null>(`/buser/delete/${ids}`)
    }
    details(id: number) {
        return requestClient.get<sellerPageListItem>(`/buser/${id}`)
    }
    
    // 批量登录
    login() {
        return requestClient.get(`/stockUser/batchLogin`)
    }
    editAvatar(id: number | string,params: { file: File }) {
        return requestClient.put(`/stockUser/editAvatar/${id}`, params, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    }
    edit(id: number | string, params: any) {
        delete params.avatarUrl
        params.assetsFrequentlyTraded = JSON.stringify(params.assetsFrequentlyTraded)
        return requestClient.put<null>(`/stockUser/edit/${id}`, params)
    }
    /**
     * 分页
     * @param params
     */
    getPageList(params: any) {
        return requestClient.get<ApiPagination<sellerPageListItem>>(
            '/stockUser/index',
            {
                params
            }
        )
    }
    // 上传文件
    upload(data: { file: File }) {
        // 使用requestClient的put方法，上传文件到/orders/importOrders接口，data为上传的文件，headers为请求头，'Content-Type'为multipart/form-data
        return requestClient.post(
            `/stockUser/import`,
            { file: data.file },
            {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }
        )
    }
    // 开始工作
    start(params: any) {
        return requestClient.post<null>('/stockUser/startWork', params)
    }
   
    // 工作详情进度
    readWorkProgress(id: number) {
        return requestClient.get(`/stockUser/readWorkProgress?workId=${id}`)
    }
    // 工作结束
    endWork(id: number) {
        return requestClient.get(`/stockUser/endWork?workId=${id}`)
    }
     // 导出
    export() {
        let url = apiURL + `/stockUser/export`
        window.open(url)
    }
    // 清空
    clear(batchNumber: string) {
        return requestClient.get(`/stockUser/clear?batchNumber=${batchNumber}`)
    }
    statuseEdit(params: Partial<sellerItemForm>) {
        return requestClient.put<null>(`/buser/edit/status/`, params)
    }
}
